﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using Caliburn.Micro;
using HandyControl.Controls;
using JY.Wpf.Core.Events;
using JY.Wpf.Core.Models;
using JY.Wpf.Core.ViewModelBases;
using JY.Wpf.Test.Views.MVVMDemoViews;
using SD.IOC.Core.Mediators;

namespace JY.Wpf.Test.ViewModels.MVVMDemoViewModels
{
    public class PageTestViewModel: PagedListChildWindowViewModelBase<PageTest>
    {
        #region # 变量

        #endregion

        #region # 构造器
        /// <summary>
        /// 构造器
        /// </summary>
        public PageTestViewModel()
        {
            this.EventAggregator.Subscribe(this);
            this.PageUpdatedAsync(1);
        }
        #endregion

        #region # 属性

        #endregion

        #region # Command方法
        #endregion

        #region # 方法

        #endregion

        #region # 加载页数据——Task<IEnumerable<T>> LoadPageAsync(int index, out int maxPageCount)

        /// <summary>
        /// 加载页数据
        /// </summary>
        /// <param name="index">页号</param>
        /// <returns></returns>
        public override Task<KeyValuePair<IEnumerable<PageTest>, int>> LoadPageAsync(int index)
        {
            var result = Task.Run(() =>
            {
                Thread.Sleep(3000);
                return GetData();
            });
            return result;
        }

        private KeyValuePair<IEnumerable<PageTest>, int> GetData()
        {
            return new KeyValuePair<IEnumerable<PageTest>, int>(new List<PageTest>(){new PageTest(),new PageTest()}, 300);
        }

        #endregion

        #region # 获取页面 —— object GetView(object context = null)
        /// <summary>
        /// 获取页面
        /// </summary>
        /// <param name="context">页面</param>
        /// <returns></returns>
        public override object GetView(object context = null)
        {
            return ResolveMediator.Resolve<PageTestView>();
        }
        #endregion
    }

    public class PageTest:ModelBase
    {
        private ObservableCollection<string> _statuses;
        private string _status;
        private bool _isSelected;

        public PageTest()
        {
            this.Statuses=new ObservableCollection<string>(){"状态1", "状态2", "状态3", "状态4" };
        }
        public ObservableCollection<string> Statuses
        {
            get { return this._statuses; }
            set { this._statuses = value;base.NotifyOfPropertyChange(); }
        }
        public string Status
        {
            get { return this._status; }
            set { this._status = value; base.NotifyOfPropertyChange(); }
        }

        public bool IsSelected
        {
            get { return this._isSelected; }
            set { this._isSelected = value;base.NotifyOfPropertyChange(); }
        }
    }
}
